//
//  FoodTherapyHomeView.m
//  MedicalTip
//
//  Created by 曹宇 on 15/4/13.
//  Copyright (c) 2015年 徐潇. All rights reserved.
//

#import "FoodTherapyHomeView.h"

@implementation FoodTherapyHomeView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubviews];
    }
    return self;
}
- (void)creatSubviews
{
    
    UICollectionViewFlowLayout *foodFlowOut = [[UICollectionViewFlowLayout alloc]init];
    foodFlowOut.headerReferenceSize = CGSizeMake(100, 40);
    foodFlowOut.itemSize = CGSizeMake(100, 100);
    foodFlowOut.footerReferenceSize = CGSizeMake(60, 0);
    self.foodCollectionView = [[UICollectionView alloc]initWithFrame:[[UIScreen mainScreen]bounds] collectionViewLayout:foodFlowOut];
    self.foodCollectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.foodCollectionView];
//    [_foodCollectionView release];
    
    self.foodCollectionView.delegate = self;
    self.foodCollectionView.dataSource = self;
    [self.foodCollectionView registerClass:[FoodCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
    
    [self.foodCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
    [self.foodCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    // 如果是表头区域 kind 是区域类型
    if (kind == UICollectionElementKindSectionHeader) {
        // 创建头部
        UICollectionReusableView *reusabview = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
//        reusabview.backgroundColor = [UIColor blueColor];
        reusabview.frame = CGRectMake(0, 0, self.foodCollectionView.frame.size.width, 42);
        return reusabview;
    }else
    {
        // 创建底部区域内容
        UICollectionReusableView *reuseableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footer" forIndexPath:indexPath];
//        reuseableView.backgroundColor = [UIColor yellowColor];
        return reuseableView;
    }
    
    
    
}


    
    

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FoodCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor blackColor];
    return cell;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
